<style lang="less">
@import "../less/editable-table.less";
</style>

<template>
    <div>
        <Table border :columns="columns" :data="tableData"></Table>
        <Modal v-model="removeModel" width="360">
            <p slot="header" style="color:#f60;">
                <Icon type="md-information-circled"></Icon>
                <span>删除提示</span>
            </p>
            <div style="text-align:center">
                <p style="font-size:18px;">数据删除后不可恢复，请谨慎操作！</p>
            </div>
            <div slot="footer">
                <Button type="error" @click="remove()" size="large">删除</Button>
                <Button type="info" @click="noRemove()" size="large">取消</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
import ajax from '../../../../libs/axios.js'
export default {
    props: {
        tableData: Array,
        access: Object
    },
    data () {
        return {
            removeModel:false,
            partyModel: false,
            id: '',
            partySection: {},
            itemTotal: 0,
            mobile: '',
            columns: [
                {
                    title: '#',
                    type: 'index',
                    width: 50,
                    align: 'center'
                },
                {
                    title: '车型',
                    align: 'center',
                    width: 260,
                    key: 'model'
                },
                {
                    title: '规格',
                    align: 'center',
                    width: 65,
                    key: 'specification'
                },
                {
                    title: '指导价',
                    align: 'center',
                    width: 80,
                    key: 'guidance_PRICE'
                },
                {
                    title: '状态',
                    align: 'center',
                    width: 65,
                    key: 'car_STATUS'
                },
                {
                    title: '4S店名',
                    align: 'center',
                    width: 110,
                    key: 'party_NAME'
                },
                {
                    title: '人员名称',
                    align: 'center',
                    width: 110,
                    key: 'login_NAME'
                },
                {
                    title: '车架号',
                    align: 'center',
                    width: 90,
                    key: 'vin'
                },
                {
                    title: '外观',
                    align: 'center',
                    width: 65,
                    key: 'out_COLOR'
                },
                {
                    title: '内饰',
                    align: 'center',
                    width: 65,
                    key: 'in_COLOR'
                },
                {
                    title: '所在地',
                    align: 'center',
                    width: 75,
                    key: 'car_LOCATION'
                },
                {
                    title: '状态',
                    align: 'center',
                    width: 100,
                    key: 'status',
                    render: (h, params) => {
                        if (params.row.status === -1) {
                            return h('span', '删除')
                        }else if(params.row.status === 0) {
                            return h('span', '未审核')
                        }else if(params.row.status === 1) {
                            return h('span', '下架')
                        }else if(params.row.status === 2) {
                            return h('span', '上架')
                        }else if(params.row.status === 3) {
                            return h('span', '推荐')
                        }
                    }
                },
                {
                    title: '创建时间',
                    align: 'center',
                    width: 180,
                    key: 'create_TIME'
                },
                {
                    title: '操作',
                    key: 'action',
                    width: 180,
                    fixed: 'right',
                    align: 'center',
                    render: (h, params) => {
                        return h('div', [
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.goRemove(params.index, params.row.id)
                                        }
                                    }
                                },
                                '删除'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'info',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight:'5px'
                                    },
                                    on: {
                                        click: () => {
                                             this.editData(params.row.id)
                                        }
                                    }
                                },
                                '修改'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'success',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight:'1px',
                                        display: params.row.status == 2 ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                             this.setData(params.row.id,params.index,1)
                                        }
                                    }
                                },
                                '下架'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'warning',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight:'1px',
                                        display: params.row.status == 1 ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                             this.setData(params.row.id,params.index,2)
                                        }
                                    }
                                },
                                '上架'
                            )
                        ])
                    }
                }
            ],
            partyData: [],
            data: [],
            partyId:''
        }
    },

    methods: {
        init () {
            this.partyData = [];
        },
        editData (id) {
            let argu = {
                id: id
            }
            this.$router.push({
                name: 'editrealcar',
                params: argu
            })
        },
        goRemove (index, id) {
            this.modal = true
            this.id = id
            this.index = index
            this.removeModel = true
        },
        remove () {
            let url = 'adminlogin/carsource/updateInfoById'
            let data = {
                ID: this.id,
                STATUS:-1
            }
            ajax.formRes(url, data).then(res => {
                    if (res.data > 0) {
                        this.tableData.splice(this.index, 1)
                        // this.tableData[this.index].status = 0;
                        this.removeModel = false
                    }
            }).catch(res => {
                console.log('有错误信息')
                // fail
            })
        },
        noRemove () {
            this.removeModel = false
        },
        cancel () {
            this.partySection = {}
            this.partyModel = false
        },
        ok () {
            this.partyId = this.partySection.id
            //更新用户的企业信息
            let that = this
            let data = {
                id:this.id,
                partyId:this.partySection.id
            }
            let url = 'adminlogin/updateCjUser'
            ajax.formRes(url, data).then(res => {
                // success
                that.$Message.success('数据设置成功,页面正在跳转')
                let argu = {}
                that.$router.push({
                    name: 'personalindex',
                    params: argu
                })
            }).catch(res => {
                console.log('有错误信息')
                // fail
            })

        },
        partyChange (section) {
            console.log(section)
            this.partySection = section
        },

        // 修改数据
        setData (id,index,status) {
            //设置参数
            let that = this
            let data1 = {
                ID:id,
                STATUS:status
            }
            let url = 'adminlogin/carsource/updateInfoById'
            ajax.formRes(url, data1).then(res => {
                        // success
                that.tableData[index].status = status;
            }).catch(res => {
                console.log('有错误信息')
                // fail
            })
        },


        getList (page) {

        }
    },
    created: function () {
        this.init()
    },
    activated () {
        this.init()
    }
}
</script>
